$(function() {
    $('#com_bottom').load('../assets/public/html/PublicBottom.html');

    //公司简介互切换招聘职位
    $('.pro_company_profile_div').click(function() {
        $('.comp_body_pro').show();
        $('.comp_body_position').hide();
        $('.pro_recruitment_position').css('font-weight', '400');
        $('.pro_company_profile').css('font-weight', 'bold');
        $('.pro_xian').css('display', 'block');
        $('.pos_xian').hide();
    });
    $('.pro_recruitment_position_div').click(function() {
        $('.comp_body_position').show();
        $('.comp_body_pro').hide();
        $('.pro_company_profile').css('font-weight', '400');
        $('.pro_recruitment_position').css('font-weight', 'bold');
        $('.pos_xian').css('display', 'block');
        $('.pro_xian').hide();
    });

    // 公司信息
    function ComInf() {
        var pageURL = $(location).attr("href");
        var comid = pageURL.split("=");
        var last_comid = comid[1]; //获取id
        let Com_Inf = Interceptor('/company', 'post', {
            'company_id': last_comid //公司id
        });
        if (Com_Inf.message == "该公司信息错误") {
            $('.com-back-center').show();
            $('.com-back-left').hide();
            $('.com-back-right').hide();
            $('#comp_body').hide();
        } else {
            $('.com-back-center').hide();
            const ComInfTetle = `
                <img src="${Com_Inf.data[0].company_logo}" alt="" class="com-back-left-img" alt="" class="com-back-left-img">
                <h3>${Com_Inf.data[0].company_name}</h3>
                <p class="com-back-left-p">
                    <img src="https://19jwshow.oss-cn-shenzhen.aliyuncs.com/recruit/icon/Number_of_people1.png" alt="" class="com-back-aaa">
                    <span class="com-back-left-span">${Com_Inf.data[0].com_official}</span>${Com_Inf.data[1].management}
                </p>
            `
            $('.com-back-left').append(ComInfTetle);
            const ComInfBody = `
                <p>${Com_Inf.data[0].company_introduction}</p>
            `
            $('.comp_body_pro_con').append(ComInfBody);
            for (let i = 0; i < Com_Inf.data[2].length; i++) {
                if (Com_Inf.data[2][i].coenviron_img != null) {
                    const ComInfBodyImg = `
                    <img src="${Com_Inf.data[2][i].coenviron_img}" alt="">
                `
                    $('.comp_body_en_nei').append(ComInfBodyImg);
                }
            }
            const ComBodyWel = `
                <li>
                    <dd><span class="wel_con_se">1</span>、${Com_Inf.data[0].company_welfare}</dd>
                    <p><span>${Com_Inf.data[0].company_welfare}</span></p>
                </li>
            `
            $('.comp_body_wel_con > ul').append(ComBodyWel);
            for (let i = 0; i < Com_Inf.data[3].length; i++) {
                const ComTailorism = `
                <div class="pro_tailorism_two">
                    <div class="pro_tal_img">
                        <img src="${Com_Inf.data[3][i].product_img}" alt="">
                    </div>
                    <div class="pro_tal_tile">
                        <dd>${Com_Inf.data[3][i].coproduct}</dd>
                        <dt>${Com_Inf.data[3][i].productType}<span class="xin_se_o">${Com_Inf.data[3][i].productType}</span></dt>
                        <p>${Com_Inf.data[3][i].product_introduction}</p>
                    </div>
                </div>
            `
                $('.comp_body_product').append(ComTailorism);
            }
            const CorName = `
                <p>${Com_Inf.data[0].company_name}</p>
            `
            $('.busi_con_corname').append(CorName);
            var com_addtime = Com_Inf.data[1].company_addtime;
            var company_time = new Date(com_addtime * 1000).toLocaleDateString();
            const ConEstime = `
                <p>${company_time}</p>
            `
            $('.busi_con_estime').append(ConEstime);
            const ConRegcap = `
                <p>${Com_Inf.data[1].add_money}</p>
            `
            $('.busi_con_regcap').append(ConRegcap);
            const ConLegrep = `
                <p>${Com_Inf.data[1].username}</p>
            `
            $('.busi_con_legrep').append(ConLegrep);
            const ConComtype = `
                <p>${Com_Inf.data[1].management}</p>
            `
            $('.busi_con_comtype').append(ConComtype);
            const ConNatofbu = `
                <p>${Com_Inf.data[1].management}</p>
            `
            $('.busi_con_natofbu').append(ConNatofbu);
            $('.busi_con_natofbu > p').css({
                'text-align': 'left',
                'margin-left': '40px'
            });
            const Conadd = `
                <span>公司地址：<strong>${Com_Inf.data[0].company_area}</strong></span>
            `
            $('.add_tile').append(Conadd);
        };
    }
    ComInf();

    //返回公司人事
    function userCom() {
        var pageURL = $(location).attr("href");
        var comid = pageURL.split("=");
        var last_comid = comid[1]; //获取id
        let Com_user = Interceptor('/userCompany', 'post', {
            'company_id': last_comid //公司id
        });
        for (let i = 0; i < Com_user.data.length; i++) {
            const usercom = `
                <li>
                    <img src="${Com_user.data[i].header}" alt="">
                    <span>${Com_user.data[i].username}</span>
                    <p>${Com_user.data[i].mechanism}</p>
                </li>
            `
            $('.comp_body_per_con > ul').append(usercom);
        }
    }
    userCom();

    //公司职位信息
    function ComPosInf() {
        var pageURL = $(location).attr("href");
        var comid = pageURL.split("=");
        var last_comid = comid[1]; //获取id
        let ComPos_Inf = Interceptor('/companyPosition', 'post', {
            'company_id': last_comid //公司id
        });
        if (ComPos_Inf.code == 500) {
            $('.com_body_hot_not').show();
        } else {
            for (i = 0; i <= ComPos_Inf.data.length - 1; i++) {
                var create_time = ComPos_Inf.data[i].create_time;
                var datetime = new Date(create_time * 1000).toLocaleDateString();
                const ComPosInfTetle = `
                <a href="PositionDetailsPage.html?official_id=${ComPos_Inf.data[i].official_id}">
                    <div class="com_body_hot_con_box">
                        <div class="fl">
                            <dd>${ComPos_Inf.data[i].official}</dd>
                            <dt>
                                <span>${ComPos_Inf.data[i].off_area}</span>
                                <br>
                                ${datetime}
                            </dt>
                        </div>
                        <div class="fr">
                            <p>${ComPos_Inf.data[i].job_money}K</p>
                        </div>
                    </div>
                </a>
                `
                $('.com_body_hot_con').append(ComPosInfTetle);
            }
        }
    }
    ComPosInf();

    // 职业分类
    $('.com_body_job_con_selectone').click(function() {
        $('.com_body_job_con_selectone_ul').show();
        if ($('.com_body_job_con_selectone_ul').show()) {
            //将点击的li里的内容放入input中
            $('.com_body_job_con_selectone_ul > li').click(function() {
                let JobconSelectOne = $(this).text();
                $('.com_body_job_con_selectone_span').text(JobconSelectOne);
                $('.com_body_job_con_selectone_ul').hide();
                ComHotJob();
            })
        };
    }).mouseleave(function() {
        $('.com_body_job_con_selectone_ul').hide();
    });

    // 工作城市
    $('.com_body_job_con_selecttwo').click(function() {
        $('.com_body_job_con_selecttwo_ul').show();
        if ($('.com_body_job_con_selecttwo_ul').show()) {
            //将点击的li里的内容放入input中
            $('.com_body_job_con_selecttwo_ul > li').click(function() {
                let JobconSelectTwo = $(this).text();
                $('.com_body_job_con_selecttwo_span').text(JobconSelectTwo);
                $('.com_body_job_con_selecttwo_ul').hide();
                ComHotJob();
            })
        };
    }).mouseleave(function() {
        $('.com_body_job_con_selecttwo_ul').hide();
    });

    // 学历要求
    $('.com_body_job_con_selectthree').click(function() {
        $('.com_body_job_con_selectthree_ul').show();
        if ($('.com_body_job_con_selectthree_ul').show()) {
            //将点击的li里的内容放入input中
            $('.com_body_job_con_selectthree_ul > li').click(function() {
                let JobconSelectThree = $(this).text();
                $('.com_body_job_con_selectthree_span').text(JobconSelectThree);
                $('.com_body_job_con_selectthree_ul').hide();
                ComHotJob();
            })
        };
    }).mouseleave(function() {
        $('.com_body_job_con_selectthree_ul').hide();
    });

    //关注公司
    function Com_Follow() {
        var pageURL = $(location).attr("href");
        var comid = pageURL.split("=");
        var last_comid = comid[1]; //获取id
        let Com_Follow = Interceptor('/Follow', 'post', {
            'company_id': last_comid //公司id
        });
        if (Com_Follow.code == 666) {
            $('.con-back-guan-right-yi').show();
            $('.con-back-right-guan-wei').hide();
        } else {
            alert("关注失败...");
        };
    };
    $('.con-back-right-guan-wei').click(function() {
        Com_Follow();
    });

    //取消关注公司
    function Com_UnFollow() {
        var pageURL = $(location).attr("href");
        var comid = pageURL.split("=");
        var last_comid = comid[1]; //获取id
        let Com_UnFollow = Interceptor('/UnFollow', 'post', {
            'company_id': last_comid //公司id
        });
        if (Com_UnFollow.code == 666) {
            $('.con-back-right-guan-wei').show();
            $('.con-back-guan-right-yi').hide();
        } else {
            alert("取消失败...");
        };
    };
    $('.con-back-guan-right-yi').click(function() {
        Com_UnFollow();
    });


    ComHotJob();
    //返回职位分类     
    function ComHotJob() {
        $('.com_body_job_con_trainee').html('');
        let selectone = $('.com_body_job_con_selectone_span').text();
        let selecttwo = $('.com_body_job_con_selecttwo_span').text();
        let selectthree = $('.com_body_job_con_selectthree_span').text();
        if (selectone != "职业分类" && selectone != "不限" &&
            selecttwo != "工作城市" && selecttwo != "不限") {
            var type = selectone;
            var area = selecttwo;
            var edu = "";
        } else if (selectone != "职业分类" && selectone != "不限" &&
            selectthree != "学历要求" && selectthree != "不限") {
            var type = selectone;
            var area = "";
            var edu = selectthree;
        } else if (selecttwo != "工作城市" && selecttwo != "不限" &&
            selectthree != "学历要求" && selectthree != "不限") {
            var type = "";
            var area = selecttwo;
            var edu = selectthree;
        } else if (selectone != "职业分类" && selectone != "不限") {
            var type = selectone;
            var area = "";
            var edu = "";
        } else if (selecttwo != "工作城市" && selecttwo != "不限") {
            var type = "";
            var area = selecttwo;
            var edu = "";
        } else if (selectthree != "学历要求" && selectthree != "不限") {
            var type = "";
            var area = "";
            var edu = selectthree;
        } else {
            var type = "";
            var area = "";
            var edu = "";
        }
        var ComHot_Job = Interceptor('/hotOfficial', 'post', {
            'type': type,
            'area': area,
            'edu': edu
        });
        if (ComHot_Job.data.length == 0) {
            $('.com_body_job_con_trainee').html('');
            $('.com_body_job_con_trainee').html('<span class="com_body_job_con_trainee_not">没有找到数据</span>');
            $('.com_body_job_con').css('height', '180px');
            $('.com_body_job_boxa').css('border-bottom', '0px');
        } else {
            $('.com_body_job_con_trainee_not').hide();
            $('.com_body_job_con').css('height', '1040px');
        }
        for (i = 0; i <= ComHot_Job.data.length - 1; i++) {
            const ComHotJobTetle = `
                <div class="com_body_job_tr">
                    <dd>${ComHot_Job.data[i].official}</dd>
                    <a href="" class="Not_applied" onclick="ComHotJobTetle_NA($(this))" idx=${i}><span id="offid" style="display: none;" >${ComHot_Job.data[i].official_id}</span>立即应聘</a>
                    <a class="Applied">
                        <img src="https://19jwshow.oss-cn-shenzhen.aliyuncs.com/recruit/icon/icon_dui.png" alt="">已应聘
                    </a>
                    <p><span id="job_gongzhi">${ComHot_Job.data[i].range_money}</span><span title="${ComHot_Job.data[i].company_area}">${ComHot_Job.data[i].company_area}</span><span title="${ComHot_Job.data[i].company_welfare}">${ComHot_Job.data[i].company_welfare}</span></p>
                    <dt>
                        <img src="${ComHot_Job.data[i].company_logo}" alt="">
                        <span>${ComHot_Job.data[i].company_name}</span>
                    </dt>
                </div>
            `
            $('.com_body_job_con_trainee').append(ComHotJobTetle);
        }
        ComHotJobTetle_NA = function(Conarr) {
            //用户是否应聘该职位
            let offid = $('#offid').text();

            function Com_Apply() {
                let Com_Apply = Interceptor('/apply', 'post', {
                    'off_id[]': offid //职位id
                });
                if (Com_Apply.data == "没有应聘的公司") {
                    let Offid = "PositionDetailsPage.html?offid=" + offid;
                    $('.Not_applied').attr('href', Offid);
                } else {
                    const idx = Conarr.attr('idx')
                    $('.Applied').eq(idx).show();
                    $('.Not_applied').eq(idx).hide()
                }
            };
            Com_Apply();
        }
    }


});